package com.example.springbootkafka.configration;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.kafka.support.SendResult;
import org.springframework.stereotype.Component;
import org.springframework.util.concurrent.ListenableFutureCallback;


@Component
public class KafkaFutureCallback implements ListenableFutureCallback<SendResult> {

    /**
     * Spring Boot默认使用LogBack日志系统，如果不需要更改为其他日志系统如Log4j2等，则无需多余的配置，LogBack默认将日志打印到控制台上。
     */
    private static final Logger log = LoggerFactory.getLogger(KafkaFutureCallback.class);
    @Override
    public void onFailure(Throwable throwable) {
        log.error("send kafka failed: {}", throwable);
    }

    @Override
    public void onSuccess(SendResult sendResult) {
        log.info("send kafka success: {}", sendResult.getProducerRecord());
    }
}
